package com.netease.nie.base.utils;

import java.net.URL;
import java.util.Enumeration;

import org.apache.commons.lang.StringUtils;

import com.netease.nie.base.exceptions.UnexpectedException;

/**
 * 
 * @author KingsHunter
 * @createDate July 13th,2016
 *
 */
public class ClassUtils {

	private static ClassUtils classUtils = new ClassUtils();
	
	public static ClassUtils getInstance() {
		return classUtils;
	}
	
	public URL getResource(String path) {
		if (StringUtils.isNotBlank(path)) {
			URL url = this.getClass().getClassLoader().getResource(path);
			if (url != null)
				return url;
		}
		throw new UnexpectedException("无法读取路径,我艹日了狗了");
	}
	
	public Enumeration<URL> getResources(String path) {
		if (StringUtils.isNotBlank(path)) {
			try {
				Enumeration<URL> enumerations = this.getClass().getClassLoader().getResources(path);
				if (enumerations.hasMoreElements())
					return enumerations;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
